home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / term-source.lha / Extras / Source / term-Source.lha / MacroPanel.c < prev    next >
C/C++ Source or Header  |  1995-06-17  |  9KB  |  372 lines

  1. /*
  2. **    MacroPanel.c
  3. **
  4. **    Editing panel for key macro configuration
  5. **
  6. **    Copyright © 1990-1995 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12. enum    {    GAD_QUALIFIER=1,GAD_F1,GAD_F2,GAD_F3,GAD_F4,GAD_F5,GAD_F6,GAD_F7,
  13.         GAD_F8,GAD_F9,GAD_F10,GAD_USE,GAD_LOAD,GAD_SAVE,GAD_CANCEL };
  14.  
  15. BOOLEAN __regargs
  16. MacroPanel(struct MacroKeys *MacroKeys,STRPTR LastMacros,BOOLEAN Globals,struct Window *Parent)
  17. {
  18.     struct MacroKeys    *Keys;
  19.     ULONG             OldCRC;
  20.     BOOLEAN             MacroChanged = FALSE;
  21.  
  22.     OldCRC = DoCRC(MacroKeys,sizeof(struct MacroKeys));
  23.  
  24.     if(Keys = (struct MacroKeys *)AllocVecPooled(sizeof(struct MacroKeys),MEMF_ANY))
  25.     {
  26.         struct LayoutHandle *Handle;
  27.  
  28.         CopyMem(MacroKeys,Keys,sizeof(struct MacroKeys));
  29.  
  30.         if(Handle = LT_CreateHandleTags(Window -> WScreen,
  31.             LH_LocaleHook,    &LocaleHook,
  32.         TAG_DONE))
  33.         {
  34.             struct Window *PanelWindow;
  35.  
  36.             LT_New(Handle,
  37.                 LA_Type,    VERTICAL_KIND,
  38.             TAG_DONE);
  39.             {
  40.                 LT_New(Handle,
  41.                     LA_Type,    VERTICAL_KIND,
  42.                     LA_LabelID,    MSG_V36_0094,
  43.                 TAG_DONE);
  44.                 {
  45.                     LT_New(Handle,
  46.                         LA_Type,    VERTICAL_KIND,
  47.                     TAG_DONE);
  48.                     {
  49.                         LT_New(Handle,
  50.                             LA_Type,    CYCLE_KIND,
  51.                             LA_LabelID,    MSG_MACROPANEL_KEY_MODIFIER_GAD,
  52.                             LA_ID,        GAD_QUALIFIER,
  53.                             LACY_TabKey,    TRUE,
  54.                             LACY_FirstLabel,MSG_MACROPANEL_NONE_TXT,
  55.                             LACY_LastLabel,    MSG_MACROPANEL_CONTROL_TXT,
  56.                         TAG_DONE);
  57.  
  58.                         LT_New(Handle,
  59.                             LA_Type,    XBAR_KIND,
  60.                         TAG_DONE);
  61.  
  62.                         LT_EndGroup(Handle);
  63.                     }
  64.  
  65.                     LT_New(Handle,
  66.                         LA_Type,    VERTICAL_KIND,
  67.                     TAG_DONE);
  68.                     {
  69.                         STATIC STRPTR Labels[10] =
  70.                         {
  71.                             "F _1",
  72.                             "F _2",
  73.                             "F _3",
  74.                             "F _4",
  75.                             "F _5",
  76.                             "F _6",
  77.                             "F _7",
  78.                             "F _8",
  79.                             "F _9",
  80.                             "F1_0"
  81.                         };
  82.  
  83.                         LONG i;
  84.  
  85.                         for(i = 0 ; i < 10 ; i++)
  86.                         {
  87.                             LT_New(Handle,
  88.                                 LA_Type,    STRING_KIND,
  89.                                 LA_LabelText,    Labels[i],
  90.                                 LA_Chars,    40,
  91.                                 LA_ID,        GAD_F1 + i,
  92.                             TAG_DONE);
  93.                         }
  94.  
  95.                         LT_EndGroup(Handle);
  96.                     }
  97.  
  98.                     LT_EndGroup(Handle);
  99.                 }
  100.  
  101.                 LT_New(Handle,
  102.                     LA_Type,VERTICAL_KIND,
  103.                 TAG_DONE);
  104.                 {
  105.                     LT_New(Handle,
  106.                         LA_Type,    XBAR_KIND,
  107.                         LAXB_FullSize,    TRUE,
  108.                     TAG_DONE);
  109.  
  110.                     LT_EndGroup(Handle);
  111.                 }
  112.  
  113.                 LT_New(Handle,LA_Type,HORIZONTAL_KIND,
  114.                     LAGR_SameSize,    TRUE,
  115.                     LAGR_Spread,    TRUE,
  116.                 TAG_DONE);
  117.                 {
  118.                     LT_New(Handle,
  119.                         LA_Type,    BUTTON_KIND,
  120.                         LA_LabelID,    MSG_GLOBAL_USE_GAD,
  121.                         LA_ID,        GAD_USE,
  122.                         LABT_ReturnKey,    TRUE,
  123.                         LABT_ExtraFat,    TRUE,
  124.                     TAG_DONE);
  125.  
  126.                     LT_New(Handle,
  127.                         LA_Type,    BUTTON_KIND,
  128.                         LA_LabelID,    MSG_GLOBAL_LOAD_GAD,
  129.                         LA_ID,        GAD_LOAD,
  130.                         LABT_ExtraFat,    TRUE,
  131.                     TAG_DONE);
  132.  
  133.                     LT_New(Handle,
  134.                         LA_Type,    BUTTON_KIND,
  135.                         LA_LabelID,    MSG_GLOBAL_SAVE_GAD,
  136.                         LA_ID,        GAD_SAVE,
  137.                         LABT_ExtraFat,    TRUE,
  138.                     TAG_DONE);
  139.  
  140.                     LT_New(Handle,
  141.                         LA_Type,    BUTTON_KIND,
  142.                         LA_LabelID,    MSG_GLOBAL_CANCEL_GAD,
  143.                         LA_ID,        GAD_CANCEL,
  144.                         LABT_EscKey,    TRUE,
  145.                         LABT_ExtraFat,    TRUE,
  146.                     TAG_DONE);
  147.  
  148.                     LT_EndGroup(Handle);
  149.                 }
  150.  
  151.                 LT_EndGroup(Handle);
  152.             }
  153.  
  154.             if(PanelWindow = LT_Layout(Handle,LocaleString(MSG_MACROPANEL_MACRO_PREFERENCES_TXT),NULL,0,0,IDCMP_CLOSEWINDOW,0,
  155.                 LAWN_HelpHook,        &GuideHook,
  156.                 LAWN_Parent,        Parent,
  157.                 WA_DepthGadget,        TRUE,
  158.                 WA_CloseGadget,        TRUE,
  159.                 WA_DragBar,        TRUE,
  160.                 WA_RMBTrap,        TRUE,
  161.                 WA_Activate,        TRUE,
  162.             TAG_DONE))
  163.             {
  164.                 struct IntuiMessage    *Message;
  165.                 BOOLEAN             Done = FALSE;
  166.                 ULONG             MsgClass,
  167.                              MsgQualifier;
  168.                 UWORD             MsgCode;
  169.                 struct Gadget        *MsgGadget;
  170.                 UBYTE             DummyBuffer[MAX_FILENAME_LENGTH],
  171.                             *DummyChar;
  172.                 struct FileRequester    *FileRequest;
  173.                 LONG             Modifier = 0,i;
  174.  
  175.                 GuideContext(CONTEXT_MACROS);
  176.  
  177.                 PushWindow(PanelWindow);
  178.  
  179.                 LT_ShowWindow(Handle,TRUE);
  180.  
  181.                 if(XEmulatorBase && Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Globals)
  182.                 {
  183.                     ULONG KeyMask = XEmulatorGetFreeMacroKeys(XEM_IO,Modifier);
  184.  
  185.                     for(i = 0 ; i < 10 ; i++)
  186.                     {
  187.                         LT_SetAttributes(Handle,GAD_F1 + i,
  188.                             GTST_String,    Keys -> Keys[Modifier][i],
  189.                             GA_Disabled,    !(KeyMask & (1L << i)),
  190.                         TAG_DONE);
  191.                     }
  192.                 }
  193.                 else
  194.                 {
  195.                     for(i = 0 ; i < 10 ; i++)
  196.                     {
  197.                         LT_SetAttributes(Handle,GAD_F1 + i,
  198.                             GTST_String,    Keys -> Keys[Modifier][i],
  199.                         TAG_DONE);
  200.                     }
  201.                 }
  202.  
  203.                 do
  204.                 {
  205.                     if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
  206.                     {
  207.                         CopyMem(Keys,MacroKeys,sizeof(struct MacroKeys));
  208.  
  209.                         break;
  210.                     }
  211.  
  212.                     while(Message = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort))
  213.                     {
  214.                         MsgClass    = Message -> Class;
  215.                         MsgQualifier    = Message -> Qualifier;
  216.                         MsgCode        = Message -> Code;
  217.                         MsgGadget    = (struct Gadget *)Message -> IAddress;
  218.  
  219.                         GT_ReplyIMsg(Message);
  220.  
  221.                         LT_HandleInput(Handle,MsgQualifier,&MsgClass,&MsgCode,&MsgGadget);
  222.  
  223.                         if(MsgClass == IDCMP_CLOSEWINDOW)
  224.                         {
  225.                             CopyMem(Keys,MacroKeys,sizeof(struct MacroKeys));
  226.  
  227.                             Done = TRUE;
  228.                         }
  229.  
  230.                         if(MsgClass == IDCMP_GADGETUP)
  231.                         {
  232.                             switch(MsgGadget -> GadgetID)
  233.                             {
  234.                                 case GAD_QUALIFIER:
  235.  
  236.                                     for(i = 0 ; i < 10 ; i++)
  237.                                         strcpy(Keys -> Keys[Modifier][i],(STRPTR)LT_GetAttributes(Handle,GAD_F1 + i,TAG_DONE));
  238.  
  239.                                     Modifier = MsgCode;
  240.  
  241.                                     if(XEmulatorBase && Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Globals)
  242.                                     {
  243.                                         ULONG KeyMask = XEmulatorGetFreeMacroKeys(XEM_IO,Modifier);
  244.  
  245.                                         for(i = 0 ; i < 10 ; i++)
  246.                                         {
  247.                                             LT_SetAttributes(Handle,GAD_F1 + i,
  248.                                                 GTST_String,    Keys -> Keys[Modifier][i],
  249.                                                 GA_Disabled,    !(KeyMask & (1L << i)),
  250.                                             TAG_DONE);
  251.                                         }
  252.                                     }
  253.                                     else
  254.                                     {
  255.                                         for(i = 0 ; i < 10 ; i++)
  256.                                         {
  257.                                             LT_SetAttributes(Handle,GAD_F1 + i,
  258.                                                 GTST_String,Keys -> Keys[Modifier][i],
  259.                                             TAG_DONE);
  260.                                         }
  261.                                     }
  262.  
  263.                                     break;
  264.  
  265.                                 case GAD_USE:
  266.  
  267.                                     for(i = 0 ; i < 10 ; i++)
  268.                                         strcpy(Keys -> Keys[Modifier][i],(STRPTR)LT_GetAttributes(Handle,GAD_F1 + i,TAG_DONE));
  269.  
  270.                                     CopyMem(Keys,MacroKeys,sizeof(struct MacroKeys));
  271.  
  272.                                     Done = TRUE;
  273.                                     break;
  274.  
  275.                                 case GAD_LOAD:
  276.  
  277.                                     strcpy(DummyBuffer,LastMacros);
  278.  
  279.                                     DummyChar = PathPart(DummyBuffer);
  280.  
  281.                                     *DummyChar = 0;
  282.  
  283.                                     LT_LockWindow(PanelWindow);
  284.  
  285.                                     if(FileRequest = GetFile(PanelWindow,LocaleString(MSG_MACROPANEL_LOAD_MACRO_KEYS_TXT),DummyBuffer,FilePart(LastMacros),DummyBuffer,"#?.prefs",FALSE,FALSE,FALSE,LocaleString(MSG_GLOBAL_LOAD_TXT),TRUE))
  286.                                     {
  287.                                         if(!LoadMacros(DummyBuffer,Keys))
  288.                                             ShowError(PanelWindow,ERR_LOAD_ERROR,IoErr(),DummyBuffer);
  289.                                         else
  290.                                         {
  291.                                             MacroChanged = FALSE;
  292.  
  293.                                             OldCRC = DoCRC(Keys,sizeof(struct MacroKeys));
  294.  
  295.                                             strcpy(Config -> FileConfig -> MacroFileName,DummyBuffer);
  296.  
  297.                                             strcpy(LastMacros,DummyBuffer);
  298.  
  299.                                             for(i = 0 ; i < 10 ; i++)
  300.                                             {
  301.                                                 LT_SetAttributes(Handle,GAD_F1 + i,
  302.                                                     GTST_String,Keys -> Keys[Modifier][i],
  303.                                                 TAG_DONE);
  304.                                             }
  305.                                         }
  306.  
  307.                                         FreeAslRequest(FileRequest);
  308.                                     }
  309.  
  310.                                     LT_UnlockWindow(PanelWindow);
  311.  
  312.                                     break;
  313.  
  314.                                 case GAD_SAVE:
  315.  
  316.                                     strcpy(DummyBuffer,LastMacros);
  317.  
  318.                                     DummyChar = PathPart(DummyBuffer);
  319.  
  320.                                     *DummyChar = 0;
  321.  
  322.                                     LT_LockWindow(PanelWindow);
  323.  
  324.                                     for(i = 0 ; i < 10 ; i++)
  325.                                         strcpy(Keys -> Keys[Modifier][i],(STRPTR)LT_GetAttributes(Handle,GAD_F1 + i,TAG_DONE));
  326.  
  327.                                     if(FileRequest = GetFile(PanelWindow,LocaleString(MSG_MACROPANEL_SAVE_MACRO_KEYS_TXT),DummyBuffer,FilePart(LastMacros),DummyBuffer,"#?.prefs",TRUE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SAVE_TXT),TRUE))
  328.                                     {
  329.                                         if(!WriteIFFData(DummyBuffer,Keys,sizeof(struct MacroKeys),ID_KEYS))
  330.                                             ShowError(PanelWindow,ERR_SAVE_ERROR,IoErr(),DummyBuffer);
  331.                                         else
  332.                                         {
  333.                                             strcpy(LastMacros,DummyBuffer);
  334.  
  335.                                             MacroChanged = FALSE;
  336.  
  337.                                             OldCRC = DoCRC(Keys,sizeof(struct MacroKeys));
  338.                                         }
  339.  
  340.                                         FreeAslRequest(FileRequest);
  341.                                     }
  342.  
  343.                                     LT_UnlockWindow(PanelWindow);
  344.  
  345.                                     break;
  346.  
  347.                                 case GAD_CANCEL:
  348.  
  349.                                     CopyMem(Keys,MacroKeys,sizeof(struct MacroKeys));
  350.  
  351.                                     Done = TRUE;
  352.                                     break;
  353.                             }
  354.                         }
  355.                     }
  356.                 }
  357.                 while(!Done);
  358.  
  359.                 PopWindow();
  360.             }
  361.  
  362.             LT_DeleteHandle(Handle);
  363.         }
  364.  
  365.         FreeVecPooled(Keys);
  366.     }
  367.  
  368.     MacroChanged |= (OldCRC != DoCRC(MacroKeys,sizeof(struct MacroKeys)));
  369.  
  370.     return(MacroChanged);
  371. }
  372.